/*
 * Copyright (C) 2010 Tani Group 
 * http://android-demo.blogspot.com/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ua.at.tsvetkov.ui.menus;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.widget.Toast;

/**
 * Main activity for the sample
 * @author nguyendt
 */
public class IconContextMenuExample extends Activity {

	private final int			CONTEXT_MENU_ID		= 1;
	private IconContextMenu	iconContextMenu		= null;

	private final int			MENU_ITEM_1_ACTION	= 1;
	private final int			MENU_ITEM_2_ACTION	= 2;
	private final int			MENU_ITEM_3_ACTION	= 3;
	private final int			MENU_ITEM_4_ACTION	= 4;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.icon_context_menu);

		
		// init sample list for test
		initSampleList();

		// init the menu
//		iconContextMenu = new IconContextMenu(this, CONTEXT_MENU_ID);
//		iconContextMenu.addItem("Menu Item 1", R.drawable.delete, MENU_ITEM_1_ACTION);
//		iconContextMenu.addItem("Menu Item 2", R.drawable.delete_all, MENU_ITEM_2_ACTION);
//		iconContextMenu.addItem("Menu Item 3", R.drawable.delete_all, MENU_ITEM_3_ACTION);
//		iconContextMenu.addItem("Menu Item 4", R.drawable.to_favotites, MENU_ITEM_4_ACTION);

		// set onclick listener for context menu
		iconContextMenu.setOnClickListener(new IconContextMenu.IconContextMenuOnClickListener() {
			public void onClick(int menuId) {
				switch (menuId) {
					case MENU_ITEM_1_ACTION:
						Toast.makeText(getApplicationContext(), "You've clicked on menu item 1", Toast.LENGTH_SHORT).show();
						break;
					case MENU_ITEM_2_ACTION:
						Toast.makeText(getApplicationContext(), "You've clicked on menu item 2", Toast.LENGTH_SHORT).show();
						break;
					case MENU_ITEM_3_ACTION:
						Toast.makeText(getApplicationContext(), "You've clicked on menu item 3", Toast.LENGTH_SHORT).show();
						break;
					case MENU_ITEM_4_ACTION:
						Toast.makeText(getApplicationContext(), "You've clicked on menu item 4", Toast.LENGTH_SHORT).show();
						break;
				}
			}
		});
	}

	/**
	 * initialize sample list for demo application
	 */
	private void initSampleList() {
//		ListView lv = (ListView) this.findViewById(R.id.sampleList);
//		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, new String[] { "List Item 1", "List Item 2", "List Item 3", "List Item 4",
//				"List Item 5", "List Item 6", "List Item 7", "List Item 8" });
//		lv.setAdapter(adapter);
//		lv.setOnItemLongClickListener(itemLongClickHandler);
	}

	/**
	 * list item long click handler used to show the context menu
	 */
//	private OnItemLongClickListener	itemLongClickHandler	= new OnItemLongClickListener() {
//
//																				public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
//																					showDialog(CONTEXT_MENU_ID);
//																					return true;
//																				}
//																			};

	/**
	 * create context menu
	 */
	@SuppressWarnings("deprecation")
	@Override
	protected Dialog onCreateDialog(int id) {
		if (id == CONTEXT_MENU_ID) {
			return iconContextMenu.createMenu("Menu Title");
		}
		return super.onCreateDialog(id);
	}
}
